package com.mc.servlet;

import com.mc.bean.Student;
import com.mc.service.StudentService;
import com.mc.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @zh
 * 学生列表
 */
@WebServlet("/studentlist.action")
public class StudentListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //创建部门业务逻辑对象
        StudentService studentService=new StudentServiceImpl();
        //得到值
        List<Student> studentList = studentService.findAll();
        req.setAttribute("studentlist",studentList);
        System.out.println(studentList);
        //转发
        req.getRequestDispatcher("studentalist.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
